package com.wk.pay.controller;

import com.wk.common.bean.Resp;
import com.wk.common.constant.mq.ItemExchange;
import com.wk.common.constant.mq.ItemRoutingKey;
import com.wk.pay.vo.PayAsyncVo;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("pay")
public class PayController {

    @Autowired
    private AmqpTemplate amqpTemplate;

    /**
     * 支付宝支付成功后的回调方法
     * 发送订单编号到消息队列 监听并更改订单状态 减库存 加积分
     */
    @PostMapping
    public Resp<Void>paySuccess(PayAsyncVo payAsyncVo){

        amqpTemplate.convertAndSend(ItemExchange.ORDER_EXCHANGE, ItemRoutingKey.PAY_SUCCESS,payAsyncVo.getOut_trade_no());

        return Resp.ok(null);
    }

}
